#ifndef CTREEITEM_H
#define CTREEITEM_H

#include "cdatabase.h"

#include <QIcon>
#include <QList>

class CTreeItem
{
    QList<CTreeItem*> m_items;

    CDatabase &m_db;
    QString m_id;
    CTreeItem *m_parent;

    QMap<QString, QVariant> m_data;
    QString m_icon_id;

    bool getData();
    void debug(QString msg) const { qDebug() << "[TreeItem]\t" + msg; }

public:
    CTreeItem(CDatabase &db, QString id, CTreeItem *parent = 0);
    ~CTreeItem();

    void appendChild(CTreeItem *child);

    CTreeItem *child(int row);
    int childCount() const;

    enum
    {
        Icon,
        Name,
        Id,
        IconId,
        Parent
    };

    static QString getStringById(int id);

    QVariant icon();
    QVariant name();
    QString id();
    int entries();
    QString icon_id();

    int row() const;
    CTreeItem *parent();
    
    void clear();

    void deleteChild(CTreeItem*);

    CTreeItem* findById(QString);
    int findChildRow(QString);
};

#endif // CTREEITEM_H
